Skip to content

Commit 8365fcb

Browse files
committed
Auto merge of #145589 - Zalathar:rollup-k97wtuq, r=Zalathar
Rollup of 19 pull requests Successful merges: - #140956 (`impl PartialEq<{str,String}> for {Path,PathBuf}`) - #141744 (Stabilize `ip_from`) - #142681 (Remove the `#[no_sanitize]` attribute in favor of `#[sanitize(xyz = "on|off")]`) - #142871 (Trivial improve doc for transpose ) - #144252 (Do not copy .rmeta files into the sysroot of the build compiler during check of rustc/std) - #144476 (rustdoc-search: search backend with partitioned suffix tree) - #144567 (Fix RISC-V Test Failures in ./x test for Multiple Codegen Cases) - #144804 (Don't warn on never to any `as` casts as unreachable) - #144960 ([RTE-513] Ignore sleep_until test on SGX) - #145013 (overhaul `&mut` suggestions in borrowck errors) - #145041 (rework GAT borrowck limitation error) - #145243 (take attr style into account in diagnostics) - #145405 (cleanup: use run_in_tmpdir in run-make/rustdoc-scrape-examples-paths) - #145432 (cg_llvm: Small cleanups to `owned_target_machine`) - #145484 (Remove `LlvmArchiveBuilder` and supporting code/bindings) - #145557 (Fix uplifting in `Assemble` step) - #145563 (Remove the `From` derive macro from prelude) - #145565 (Improve context of bootstrap errors in CI) - #145584 (interpret: avoid forcing all integer newtypes into memory during clear_provenance) Failed merges: - #145359 (Fix bug where `rustdoc-js` tester would not pick the right `search.js` file if there is more than one) - #145573 (Add an experimental unsafe(force_target_feature) attribute.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b96868f + 531ec85 commit 8365fcb

File tree

282 files changed

+11390
-6660
lines changed

Some content is hidden

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

282 files changed

+11390
-6660
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,6 +4812,7 @@ dependencies = [
48124812
"serde_json",
48134813
"sha2",
48144814
"smallvec",
4815+
"stringdex",
48154816
"tempfile",
48164817
"threadpool",
48174818
"tracing",
@@ -5225,6 +5226,15 @@ dependencies = [
52255226
"quote",
52265227
]
52275228

5229+
[[package]]
5230+
name = "stringdex"
5231+
version = "0.0.1-alpha4"
5232+
source = "registry+https://github.com/rust-lang/crates.io-index"
5233+
checksum = "2841fd43df5b1ff1b042e167068a1fe9b163dc93041eae56ab2296859013a9a0"
5234+
dependencies = [
5235+
"stacker",
5236+
]
5237+
52285238
[[package]]
52295239
name = "strsim"
52305240
version = "0.11.1"

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
6262
}
6363
}
6464
ArgParser::NameValue(_) => {
65-
let suggestions =
66-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "inline");
65+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
66+
.suggestions(cx.attr_style, "inline");
6767
let span = cx.attr_span;
6868
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
6969
return None;

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
107107
}
108108
}
109109
ArgParser::NameValue(_) => {
110-
let suggestions = MACRO_USE_TEMPLATE.suggestions(false, sym::macro_use);
110+
let suggestions = MACRO_USE_TEMPLATE.suggestions(cx.attr_style, sym::macro_use);
111111
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
112112
num_suggestions: suggestions.len(),
113113
suggestions: DiagArgValue::StrListSepByAnd(

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
3535
Some(value_str)
3636
}
3737
ArgParser::List(_) => {
38-
let suggestions =
39-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "must_use");
38+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
39+
.suggestions(cx.attr_style, "must_use");
4040
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
4141
num_suggestions: suggestions.len(),
4242
suggestions: DiagArgValue::StrListSepByAnd(

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
2929
ArgParser::NameValue(name_value) => {
3030
let Some(str_value) = name_value.value_as_str() else {
3131
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
32-
.suggestions(false, "ignore");
32+
.suggestions(cx.attr_style, "ignore");
3333
let span = cx.attr_span;
3434
cx.emit_lint(
3535
AttributeLintKind::IllFormedAttributeInput { suggestions },
@@ -40,8 +40,8 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
4040
Some(str_value)
4141
}
4242
ArgParser::List(_) => {
43-
let suggestions =
44-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
43+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
44+
.suggestions(cx.attr_style, "ignore");
4545
let span = cx.attr_span;
4646
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
4747
return None;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::LazyLock;
55

66
use itertools::Itertools;
77
use private::Sealed;
8-
use rustc_ast::{self as ast, LitKind, MetaItemLit, NodeId};
8+
use rustc_ast::{self as ast, AttrStyle, LitKind, MetaItemLit, NodeId};
99
use rustc_errors::{DiagCtxtHandle, Diagnostic};
1010
use rustc_feature::{AttributeTemplate, Features};
1111
use rustc_hir::attrs::AttributeKind;
@@ -315,6 +315,7 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
315315
/// The span of the attribute currently being parsed
316316
pub(crate) attr_span: Span,
317317

318+
pub(crate) attr_style: AttrStyle,
318319
/// The expected structure of the attribute.
319320
///
320321
/// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -396,6 +397,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
396397
i.kind.is_bytestr().then(|| self.sess().source_map().start_point(i.span))
397398
}),
398399
},
400+
attr_style: self.attr_style,
399401
})
400402
}
401403

@@ -406,6 +408,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
406408
template: self.template.clone(),
407409
attribute: self.attr_path.clone(),
408410
reason: AttributeParseErrorReason::ExpectedIntegerLiteral,
411+
attr_style: self.attr_style,
409412
})
410413
}
411414

@@ -416,6 +419,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
416419
template: self.template.clone(),
417420
attribute: self.attr_path.clone(),
418421
reason: AttributeParseErrorReason::ExpectedList,
422+
attr_style: self.attr_style,
419423
})
420424
}
421425

@@ -426,6 +430,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
426430
template: self.template.clone(),
427431
attribute: self.attr_path.clone(),
428432
reason: AttributeParseErrorReason::ExpectedNoArgs,
433+
attr_style: self.attr_style,
429434
})
430435
}
431436

@@ -437,6 +442,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
437442
template: self.template.clone(),
438443
attribute: self.attr_path.clone(),
439444
reason: AttributeParseErrorReason::ExpectedIdentifier,
445+
attr_style: self.attr_style,
440446
})
441447
}
442448

@@ -449,6 +455,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
449455
template: self.template.clone(),
450456
attribute: self.attr_path.clone(),
451457
reason: AttributeParseErrorReason::ExpectedNameValue(name),
458+
attr_style: self.attr_style,
452459
})
453460
}
454461

@@ -460,6 +467,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
460467
template: self.template.clone(),
461468
attribute: self.attr_path.clone(),
462469
reason: AttributeParseErrorReason::DuplicateKey(key),
470+
attr_style: self.attr_style,
463471
})
464472
}
465473

@@ -472,6 +480,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
472480
template: self.template.clone(),
473481
attribute: self.attr_path.clone(),
474482
reason: AttributeParseErrorReason::UnexpectedLiteral,
483+
attr_style: self.attr_style,
475484
})
476485
}
477486

@@ -482,6 +491,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
482491
template: self.template.clone(),
483492
attribute: self.attr_path.clone(),
484493
reason: AttributeParseErrorReason::ExpectedSingleArgument,
494+
attr_style: self.attr_style,
485495
})
486496
}
487497

@@ -492,6 +502,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
492502
template: self.template.clone(),
493503
attribute: self.attr_path.clone(),
494504
reason: AttributeParseErrorReason::ExpectedAtLeastOneArgument,
505+
attr_style: self.attr_style,
495506
})
496507
}
497508

@@ -510,6 +521,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
510521
strings: false,
511522
list: false,
512523
},
524+
attr_style: self.attr_style,
513525
})
514526
}
515527

@@ -528,6 +540,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
528540
strings: false,
529541
list: true,
530542
},
543+
attr_style: self.attr_style,
531544
})
532545
}
533546

@@ -546,6 +559,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
546559
strings: true,
547560
list: false,
548561
},
562+
attr_style: self.attr_style,
549563
})
550564
}
551565

@@ -804,6 +818,7 @@ impl<'sess> AttributeParser<'sess, Early> {
804818
},
805819
},
806820
attr_span: attr.span,
821+
attr_style: attr.style,
807822
template,
808823
attr_path: path.get_attribute_path(),
809824
};
@@ -914,6 +929,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
914929
emit_lint: &mut emit_lint,
915930
},
916931
attr_span: lower_span(attr.span),
932+
attr_style: attr.style,
917933
template: &accept.template,
918934
attr_path: path.get_attribute_path(),
919935
};

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::num::IntErrorKind;
22

3-
use rustc_ast as ast;
3+
use rustc_ast::{self as ast, AttrStyle};
44
use rustc_errors::codes::*;
55
use rustc_errors::{
66
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level,
@@ -579,6 +579,7 @@ pub(crate) enum AttributeParseErrorReason {
579579
pub(crate) struct AttributeParseError {
580580
pub(crate) span: Span,
581581
pub(crate) attr_span: Span,
582+
pub(crate) attr_style: AttrStyle,
582583
pub(crate) template: AttributeTemplate,
583584
pub(crate) attribute: AttrPath,
584585
pub(crate) reason: AttributeParseErrorReason,
@@ -717,7 +718,8 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
717718
if let Some(link) = self.template.docs {
718719
diag.note(format!("for more information, visit <{link}>"));
719720
}
720-
let suggestions = self.template.suggestions(false, &name);
721+
let suggestions = self.template.suggestions(self.attr_style, &name);
722+
721723
diag.span_suggestions(
722724
self.attr_span,
723725
if suggestions.len() == 1 {

compiler/rustc_borrowck/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ borrowck_lifetime_constraints_error =
9090
lifetime may not live long enough
9191
9292
borrowck_limitations_implies_static =
93-
due to current limitations in the borrow checker, this implies a `'static` lifetime
93+
due to a current limitation of the type system, this implies a `'static` lifetime
9494
9595
borrowck_move_closure_suggestion =
9696
consider adding 'move' keyword before the nested closure

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use rustc_abi::{FieldIdx, VariantIdx};
66
use rustc_data_structures::fx::FxIndexMap;
77
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
88
use rustc_hir::def::{CtorKind, Namespace};
9-
use rustc_hir::{self as hir, CoroutineKind, LangItem};
9+
use rustc_hir::{
10+
self as hir, CoroutineKind, GenericBound, LangItem, WhereBoundPredicate, WherePredicateKind,
11+
};
1012
use rustc_index::{IndexSlice, IndexVec};
1113
use rustc_infer::infer::{BoundRegionConversionTime, NllRegionVariableOrigin};
1214
use rustc_infer::traits::SelectionError;
@@ -658,25 +660,66 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
658660

659661
/// Add a note to region errors and borrow explanations when higher-ranked regions in predicates
660662
/// implicitly introduce an "outlives `'static`" constraint.
663+
///
664+
/// This is very similar to `fn suggest_static_lifetime_for_gat_from_hrtb` which handles this
665+
/// note for failed type tests instead of outlives errors.
661666
fn add_placeholder_from_predicate_note<G: EmissionGuarantee>(
662667
&self,
663-
err: &mut Diag<'_, G>,
668+
diag: &mut Diag<'_, G>,
664669
path: &[OutlivesConstraint<'tcx>],
665670
) {
666-
let predicate_span = path.iter().find_map(|constraint| {
671+
let tcx = self.infcx.tcx;
672+
let Some((gat_hir_id, generics)) = path.iter().find_map(|constraint| {
667673
let outlived = constraint.sub;
668674
if let Some(origin) = self.regioncx.definitions.get(outlived)
669-
&& let NllRegionVariableOrigin::Placeholder(_) = origin.origin
670-
&& let ConstraintCategory::Predicate(span) = constraint.category
675+
&& let NllRegionVariableOrigin::Placeholder(placeholder) = origin.origin
676+
&& let Some(id) = placeholder.bound.kind.get_id()
677+
&& let Some(placeholder_id) = id.as_local()
678+
&& let gat_hir_id = tcx.local_def_id_to_hir_id(placeholder_id)
679+
&& let Some(generics_impl) =
680+
tcx.parent_hir_node(tcx.parent_hir_id(gat_hir_id)).generics()
671681
{
672-
Some(span)
682+
Some((gat_hir_id, generics_impl))
673683
} else {
674684
None
675685
}
676-
});
686+
}) else {
687+
return;
688+
};
677689

678-
if let Some(span) = predicate_span {
679-
err.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
690+
// Look for the where-bound which introduces the placeholder.
691+
// As we're using the HIR, we need to handle both `for<'a> T: Trait<'a>`
692+
// and `T: for<'a> Trait`<'a>.
693+
for pred in generics.predicates {
694+
let WherePredicateKind::BoundPredicate(WhereBoundPredicate {
695+
bound_generic_params,
696+
bounds,
697+
..
698+
}) = pred.kind
699+
else {
700+
continue;
701+
};
702+
if bound_generic_params
703+
.iter()
704+
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
705+
.is_some()
706+
{
707+
diag.span_note(pred.span, fluent::borrowck_limitations_implies_static);
708+
return;
709+
}
710+
for bound in bounds.iter() {
711+
if let GenericBound::Trait(bound) = bound {
712+
if bound
713+
.bound_generic_params
714+
.iter()
715+
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
716+
.is_some()
717+
{
718+
diag.span_note(bound.span, fluent::borrowck_limitations_implies_static);
719+
return;
720+
}
721+
}
722+
}
680723
}
681724
}
682725

0 commit comments

Comments
 (0)