Skip to content

Commit e605a88

Browse files
committed
Auto merge of rust-lang#98438 - compiler-errors:rollup-fudubjn, r=compiler-errors
Rollup of 16 pull requests Successful merges: - rust-lang#96173 (Fix documentation for `with_capacity` and `reserve` families of methods) - rust-lang#98184 (Give name if anonymous region appears in impl signature) - rust-lang#98259 (Greatly improve error reporting for futures and generators in `note_obligation_cause_code`) - rust-lang#98269 (Provide a `PathSegment.res` in more cases) - rust-lang#98283 (Point at private fields in struct literal) - rust-lang#98305 (prohibit_generics: don't alloc error string if no error emitted) - rust-lang#98310 (rustdoc: optimize loading of source sidebar) - rust-lang#98353 (Migrate two diagnostics from the `rustc_builtin_macros` crate) - rust-lang#98355 (Update no_default_libraries handling for emscripten target) - rust-lang#98364 (clarify Arc::clone overflow check comment) - rust-lang#98365 (Address review comments from rust-lang#98259) - rust-lang#98388 (implement `iter_projections` function on `PlaceRef`) - rust-lang#98390 (Fixes handling of keywords in rustdoc json output) - rust-lang#98409 (triagebot.toml: Allow applying nominated labels) - rust-lang#98410 (Update books) - rust-lang#98422 (Update browser-ui-test version to 0.9.6) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4334739 + c9b1674 commit e605a88

File tree

87 files changed

+1119
-436
lines changed

Some content is hidden

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

87 files changed

+1119
-436
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3669,6 +3669,7 @@ dependencies = [
36693669
"rustc_feature",
36703670
"rustc_lexer",
36713671
"rustc_lint_defs",
3672+
"rustc_macros",
36723673
"rustc_parse",
36733674
"rustc_parse_format",
36743675
"rustc_session",

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ impl OutlivesSuggestionBuilder {
6262
| RegionNameSource::AnonRegionFromUpvar(..)
6363
| RegionNameSource::AnonRegionFromOutput(..)
6464
| RegionNameSource::AnonRegionFromYieldTy(..)
65-
| RegionNameSource::AnonRegionFromAsyncFn(..) => {
65+
| RegionNameSource::AnonRegionFromAsyncFn(..)
66+
| RegionNameSource::AnonRegionFromImplSignature(..) => {
6667
debug!("Region {:?} is NOT suggestable", name);
6768
false
6869
}

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+54-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir as hir;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_middle::ty::print::RegionHighlightMode;
88
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
9-
use rustc_middle::ty::{self, RegionVid, Ty};
9+
use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty};
1010
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1111
use rustc_span::{Span, DUMMY_SP};
1212

@@ -45,6 +45,8 @@ pub(crate) enum RegionNameSource {
4545
AnonRegionFromYieldTy(Span, String),
4646
/// An anonymous region from an async fn.
4747
AnonRegionFromAsyncFn(Span),
48+
/// An anonymous region from an impl self type or trait
49+
AnonRegionFromImplSignature(Span, &'static str),
4850
}
4951

5052
/// Describes what to highlight to explain to the user that we're giving an anonymous region a
@@ -75,7 +77,8 @@ impl RegionName {
7577
| RegionNameSource::AnonRegionFromUpvar(..)
7678
| RegionNameSource::AnonRegionFromOutput(..)
7779
| RegionNameSource::AnonRegionFromYieldTy(..)
78-
| RegionNameSource::AnonRegionFromAsyncFn(..) => false,
80+
| RegionNameSource::AnonRegionFromAsyncFn(..)
81+
| RegionNameSource::AnonRegionFromImplSignature(..) => false,
7982
}
8083
}
8184

@@ -87,7 +90,8 @@ impl RegionName {
8790
| RegionNameSource::SynthesizedFreeEnvRegion(span, _)
8891
| RegionNameSource::AnonRegionFromUpvar(span, _)
8992
| RegionNameSource::AnonRegionFromYieldTy(span, _)
90-
| RegionNameSource::AnonRegionFromAsyncFn(span) => Some(span),
93+
| RegionNameSource::AnonRegionFromAsyncFn(span)
94+
| RegionNameSource::AnonRegionFromImplSignature(span, _) => Some(span),
9195
RegionNameSource::AnonRegionFromArgument(ref highlight)
9296
| RegionNameSource::AnonRegionFromOutput(ref highlight, _) => match *highlight {
9397
RegionNameHighlight::MatchedHirTy(span)
@@ -166,6 +170,12 @@ impl RegionName {
166170
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
167171
diag.span_label(*span, format!("yield type is {type_name}"));
168172
}
173+
RegionNameSource::AnonRegionFromImplSignature(span, location) => {
174+
diag.span_label(
175+
*span,
176+
format!("lifetime `{self}` appears in the `impl`'s {location}"),
177+
);
178+
}
169179
RegionNameSource::Static => {}
170180
}
171181
}
@@ -240,7 +250,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
240250
.or_else(|| self.give_name_if_anonymous_region_appears_in_arguments(fr))
241251
.or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(fr))
242252
.or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
243-
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr));
253+
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr))
254+
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr));
244255

245256
if let Some(ref value) = value {
246257
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
@@ -847,4 +858,43 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
847858
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
848859
})
849860
}
861+
862+
fn give_name_if_anonymous_region_appears_in_impl_signature(
863+
&self,
864+
fr: RegionVid,
865+
) -> Option<RegionName> {
866+
let ty::ReEarlyBound(region) = *self.to_error_region(fr)? else {
867+
return None;
868+
};
869+
if region.has_name() {
870+
return None;
871+
};
872+
873+
let tcx = self.infcx.tcx;
874+
let body_parent_did = tcx.opt_parent(self.mir_def_id().to_def_id())?;
875+
if tcx.parent(region.def_id) != body_parent_did
876+
|| tcx.def_kind(body_parent_did) != DefKind::Impl
877+
{
878+
return None;
879+
}
880+
881+
let mut found = false;
882+
tcx.fold_regions(tcx.type_of(body_parent_did), &mut true, |r: ty::Region<'tcx>, _| {
883+
if *r == ty::ReEarlyBound(region) {
884+
found = true;
885+
}
886+
r
887+
});
888+
889+
Some(RegionName {
890+
name: self.synthesize_region_name(),
891+
source: RegionNameSource::AnonRegionFromImplSignature(
892+
tcx.def_span(region.def_id),
893+
// FIXME(compiler-errors): Does this ever actually show up
894+
// anywhere other than the self type? I couldn't create an
895+
// example of a `'_` in the impl's trait being referenceable.
896+
if found { "self type" } else { "header" },
897+
),
898+
})
899+
}
850900
}

compiler/rustc_builtin_macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_errors = { path = "../rustc_errors" }
1616
rustc_feature = { path = "../rustc_feature" }
1717
rustc_lexer = { path = "../rustc_lexer" }
1818
rustc_lint_defs = { path = "../rustc_lint_defs" }
19+
rustc_macros = { path = "../rustc_macros" }
1920
rustc_parse = { path = "../rustc_parse" }
2021
rustc_target = { path = "../rustc_target" }
2122
rustc_session = { path = "../rustc_session" }

compiler/rustc_builtin_macros/src/cfg.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast::tokenstream::TokenStream;
88
use rustc_attr as attr;
99
use rustc_errors::PResult;
1010
use rustc_expand::base::{self, *};
11+
use rustc_macros::SessionDiagnostic;
1112
use rustc_span::Span;
1213

1314
pub fn expand_cfg(
@@ -34,21 +35,34 @@ pub fn expand_cfg(
3435
}
3536
}
3637

37-
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
38+
#[derive(SessionDiagnostic)]
39+
#[error(slug = "builtin-macros-requires-cfg-pattern")]
40+
struct RequiresCfgPattern {
41+
#[primary_span]
42+
#[label]
43+
span: Span,
44+
}
45+
46+
#[derive(SessionDiagnostic)]
47+
#[error(slug = "builtin-macros-expected-one-cfg-pattern")]
48+
struct OneCfgPattern {
49+
#[primary_span]
50+
span: Span,
51+
}
52+
53+
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
3854
let mut p = cx.new_parser_from_tts(tts);
3955

4056
if p.token == token::Eof {
41-
let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument");
42-
err.span_label(sp, "cfg-pattern required");
43-
return Err(err);
57+
return Err(cx.create_err(RequiresCfgPattern { span }));
4458
}
4559

4660
let cfg = p.parse_meta_item()?;
4761

4862
let _ = p.eat(&token::Comma);
4963

5064
if !p.eat(&token::Eof) {
51-
return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern"));
65+
return Err(cx.create_err(OneCfgPattern { span }));
5266
}
5367

5468
Ok(cfg)

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ impl<'a> Linker for EmLinker<'a> {
11401140
fn no_crt_objects(&mut self) {}
11411141

11421142
fn no_default_libraries(&mut self) {
1143-
self.cmd.args(&["-s", "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]"]);
1143+
self.cmd.arg("-nodefaultlibs");
11441144
}
11451145

11461146
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
builtin-macros-requires-cfg-pattern =
2+
macro requires a cfg-pattern as an argument
3+
.label = cfg-pattern required
4+
5+
builtin-macros-expected-one-cfg-pattern = expected 1 cfg-pattern

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3333
fluent_messages! {
3434
parser => "../locales/en-US/parser.ftl",
3535
typeck => "../locales/en-US/typeck.ftl",
36+
builtin_macros => "../locales/en-US/builtin_macros.ftl",
3637
}
3738

3839
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

compiler/rustc_expand/src/base.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
1414
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1515
use rustc_lint_defs::BuiltinLintDiagnostics;
1616
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
17-
use rustc_session::{parse::ParseSess, Limit, Session};
17+
use rustc_session::{parse::ParseSess, Limit, Session, SessionDiagnostic};
1818
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
1919
use rustc_span::edition::Edition;
2020
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
@@ -1085,6 +1085,17 @@ impl<'a> ExtCtxt<'a> {
10851085
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
10861086
}
10871087

1088+
pub fn create_err(
1089+
&self,
1090+
err: impl SessionDiagnostic<'a>,
1091+
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
1092+
self.sess.create_err(err)
1093+
}
1094+
1095+
pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
1096+
self.sess.emit_err(err)
1097+
}
1098+
10881099
/// Emit `msg` attached to `sp`, without immediately stopping
10891100
/// compilation.
10901101
///

compiler/rustc_lint_defs/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ macro_rules! pluralize {
2626
("is", $x:expr) => {
2727
if $x == 1 { "is" } else { "are" }
2828
};
29+
("was", $x:expr) => {
30+
if $x == 1 { "was" } else { "were" }
31+
};
2932
("this", $x:expr) => {
3033
if $x == 1 { "this" } else { "these" }
3134
};

compiler/rustc_middle/src/mir/mod.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -2145,10 +2145,7 @@ impl<'tcx> Place<'tcx> {
21452145
pub fn iter_projections(
21462146
self,
21472147
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
2148-
self.projection.iter().enumerate().map(move |(i, proj)| {
2149-
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
2150-
(base, proj)
2151-
})
2148+
self.as_ref().iter_projections()
21522149
}
21532150

21542151
/// Generates a new place by appending `more_projections` to the existing ones
@@ -2208,6 +2205,23 @@ impl<'tcx> PlaceRef<'tcx> {
22082205
None
22092206
}
22102207
}
2208+
2209+
/// Iterate over the projections in evaluation order, i.e., the first element is the base with
2210+
/// its projection and then subsequently more projections are added.
2211+
/// As a concrete example, given the place a.b.c, this would yield:
2212+
/// - (a, .b)
2213+
/// - (a.b, .c)
2214+
///
2215+
/// Given a place without projections, the iterator is empty.
2216+
#[inline]
2217+
pub fn iter_projections(
2218+
self,
2219+
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
2220+
self.projection.iter().enumerate().map(move |(i, proj)| {
2221+
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
2222+
(base, *proj)
2223+
})
2224+
}
22112225
}
22122226

22132227
impl Debug for Place<'_> {

compiler/rustc_middle/src/ty/context.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use std::mem;
7474
use std::ops::{Bound, Deref};
7575
use std::sync::Arc;
7676

77-
use super::RvalueScopes;
77+
use super::{ImplPolarity, RvalueScopes};
7878

7979
pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
8080
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
@@ -2230,6 +2230,20 @@ impl<'tcx> TyCtxt<'tcx> {
22302230
})
22312231
}
22322232

2233+
/// Given a `ty`, return whether it's an `impl Future<...>`.
2234+
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
2235+
let ty::Opaque(def_id, _) = ty.kind() else { return false };
2236+
let future_trait = self.lang_items().future_trait().unwrap();
2237+
2238+
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
2239+
let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
2240+
return false;
2241+
};
2242+
trait_predicate.trait_ref.def_id == future_trait
2243+
&& trait_predicate.polarity == ImplPolarity::Positive
2244+
})
2245+
}
2246+
22332247
/// Computes the def-ids of the transitive supertraits of `trait_def_id`. This (intentionally)
22342248
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
22352249
/// to identify which traits may define a given associated type to help avoid cycle errors.

compiler/rustc_resolve/src/ident.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,7 @@ impl<'a> Resolver<'a> {
15021502
return PathResult::NonModule(PartialRes::new(Res::Err));
15031503
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
15041504
self.lint_if_path_starts_with_module(finalize, path, second_binding);
1505+
record_segment_res(self, res);
15051506
return PathResult::NonModule(PartialRes::with_unresolved_segments(
15061507
res,
15071508
path.len() - i - 1,

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub fn target() -> Target {
2828
linker: None,
2929
is_like_emscripten: true,
3030
panic_strategy: PanicStrategy::Unwind,
31+
no_default_libraries: false,
3132
post_link_args,
3233
families: cvs!["unix", "wasm"],
3334
..options

0 commit comments

Comments
 (0)