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 16 pull requests #98438

Merged
merged 40 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
95dc353
Fix documentation for with_capacity and reserve families of methods
jmaargh Apr 9, 2022
1deca04
Greatly improve error reporting for futures and generators in `note_o…
jyn514 Jun 19, 2022
1e7ab0b
point at private fields in struct literal
TaKO8Ki Jun 20, 2022
f001795
don't alloc error string if no error emitted
klensy Jun 20, 2022
b37a05b
rustdoc: optimize loading of source sidebar
jsha Jun 20, 2022
e900a35
Give name if anonymous region appears in impl signature
compiler-errors Jun 21, 2022
f924e74
Provide a segment res in more cases
compiler-errors Jun 20, 2022
761c846
Add `create_err` and `emit_err` to `ExtCtxt`
beetrees Jun 21, 2022
d6072e5
Add UI test for `cfg!(foo, bar)`
beetrees Jun 21, 2022
6264ffb
Migrate `builtin-macros-requires-cfg-pattern` to `SessionDiagnostic`
beetrees Jun 21, 2022
be5337c
Migrate `builtin-macros-expected-one-cfg-pattern` to `SessionDiagnostic`
beetrees Jun 21, 2022
8e09f42
Update Emscripten's no_default_libraries handling
hoodmane Jun 21, 2022
b052d76
Address review comments from #98259
jyn514 Jun 22, 2022
f847261
stop pointing at definitions of missing fields
TaKO8Ki Jun 22, 2022
46b2454
clarify Arc::clone overflow check comment
RalfJung Jun 22, 2022
eb86daa
add "was" to pluralize macro and use it
TaKO8Ki Jun 22, 2022
53481a5
implement `iter_projections` function on `PlaceRef`
rosefromthedead Jun 22, 2022
8e40d93
Filter out keyword items in rustdoc JSON output
GuillaumeGomez Jun 22, 2022
75ad2f7
Add test for keywords in rustdoc JSON output
GuillaumeGomez Jun 22, 2022
96cc0c6
triagebot.toml: Allow applying nominated labels
joshtriplett Jun 22, 2022
5cf5a52
triagebot.toml: Sort and wrap the list of allowed labels
joshtriplett Jun 22, 2022
24e0c44
Update books
ehuss Jun 22, 2022
b96ae9b
Set no_default_libraries: false in wasm32_emscripten target
hoodmane Jun 23, 2022
137d3c7
Update browser-ui-test version to 0.9.6
GuillaumeGomez Jun 23, 2022
262382f
Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dyl…
compiler-errors Jun 23, 2022
49bcc70
Rollup merge of #98184 - compiler-errors:elided-lifetime-in-impl-nll,…
compiler-errors Jun 23, 2022
413e350
Rollup merge of #98259 - jyn514:improve-obligation-errors, r=estebank
compiler-errors Jun 23, 2022
3b68700
Rollup merge of #98269 - compiler-errors:provide-more-segment-res, r=…
compiler-errors Jun 23, 2022
41cb5e9
Rollup merge of #98283 - TaKO8Ki:point-at-private-fields-in-struct-li…
compiler-errors Jun 23, 2022
0ed2fec
Rollup merge of #98305 - klensy:no-err-alloc, r=compiler-errors
compiler-errors Jun 23, 2022
cc95225
Rollup merge of #98310 - jsha:defer-source-sidebar, r=GuillaumeGomez
compiler-errors Jun 23, 2022
21085e9
Rollup merge of #98353 - beetrees:builtin-macros-cfg-diag, r=davidtwco
compiler-errors Jun 23, 2022
cc45ad5
Rollup merge of #98355 - hoodmane:emscripten-no-default, r=petrochenkov
compiler-errors Jun 23, 2022
e749ba2
Rollup merge of #98364 - RalfJung:arc-clone, r=Mark-Simulacrum
compiler-errors Jun 23, 2022
667a546
Rollup merge of #98365 - jyn514:improve-obligation-errors-review-comm…
compiler-errors Jun 23, 2022
aafddd2
Rollup merge of #98388 - rosehuds:master, r=davidtwco
compiler-errors Jun 23, 2022
5620983
Rollup merge of #98390 - GuillaumeGomez:keyword-rustdoc-json, r=notri…
compiler-errors Jun 23, 2022
8db945f
Rollup merge of #98409 - joshtriplett:triagebot-nominated, r=Mark-Sim…
compiler-errors Jun 23, 2022
28b92ba
Rollup merge of #98410 - ehuss:update-books, r=ehuss
compiler-errors Jun 23, 2022
c9b1674
Rollup merge of #98422 - GuillaumeGomez:browser-ui-test-update, r=Dyl…
compiler-errors Jun 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3669,6 +3669,7 @@ dependencies = [
"rustc_feature",
"rustc_lexer",
"rustc_lint_defs",
"rustc_macros",
"rustc_parse",
"rustc_parse_format",
"rustc_session",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ impl OutlivesSuggestionBuilder {
| RegionNameSource::AnonRegionFromUpvar(..)
| RegionNameSource::AnonRegionFromOutput(..)
| RegionNameSource::AnonRegionFromYieldTy(..)
| RegionNameSource::AnonRegionFromAsyncFn(..) => {
| RegionNameSource::AnonRegionFromAsyncFn(..)
| RegionNameSource::AnonRegionFromImplSignature(..) => {
debug!("Region {:?} is NOT suggestable", name);
false
}
Expand Down
58 changes: 54 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_middle::ty::print::RegionHighlightMode;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};

Expand Down Expand Up @@ -45,6 +45,8 @@ pub(crate) enum RegionNameSource {
AnonRegionFromYieldTy(Span, String),
/// An anonymous region from an async fn.
AnonRegionFromAsyncFn(Span),
/// An anonymous region from an impl self type or trait
AnonRegionFromImplSignature(Span, &'static str),
}

/// Describes what to highlight to explain to the user that we're giving an anonymous region a
Expand Down Expand Up @@ -75,7 +77,8 @@ impl RegionName {
| RegionNameSource::AnonRegionFromUpvar(..)
| RegionNameSource::AnonRegionFromOutput(..)
| RegionNameSource::AnonRegionFromYieldTy(..)
| RegionNameSource::AnonRegionFromAsyncFn(..) => false,
| RegionNameSource::AnonRegionFromAsyncFn(..)
| RegionNameSource::AnonRegionFromImplSignature(..) => false,
}
}

Expand All @@ -87,7 +90,8 @@ impl RegionName {
| RegionNameSource::SynthesizedFreeEnvRegion(span, _)
| RegionNameSource::AnonRegionFromUpvar(span, _)
| RegionNameSource::AnonRegionFromYieldTy(span, _)
| RegionNameSource::AnonRegionFromAsyncFn(span) => Some(span),
| RegionNameSource::AnonRegionFromAsyncFn(span)
| RegionNameSource::AnonRegionFromImplSignature(span, _) => Some(span),
RegionNameSource::AnonRegionFromArgument(ref highlight)
| RegionNameSource::AnonRegionFromOutput(ref highlight, _) => match *highlight {
RegionNameHighlight::MatchedHirTy(span)
Expand Down Expand Up @@ -166,6 +170,12 @@ impl RegionName {
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
diag.span_label(*span, format!("yield type is {type_name}"));
}
RegionNameSource::AnonRegionFromImplSignature(span, location) => {
diag.span_label(
*span,
format!("lifetime `{self}` appears in the `impl`'s {location}"),
);
}
RegionNameSource::Static => {}
}
}
Expand Down Expand Up @@ -240,7 +250,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
.or_else(|| self.give_name_if_anonymous_region_appears_in_arguments(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr));
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr));

if let Some(ref value) = value {
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
Expand Down Expand Up @@ -847,4 +858,43 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
})
}

fn give_name_if_anonymous_region_appears_in_impl_signature(
&self,
fr: RegionVid,
) -> Option<RegionName> {
let ty::ReEarlyBound(region) = *self.to_error_region(fr)? else {
return None;
};
if region.has_name() {
return None;
};

let tcx = self.infcx.tcx;
let body_parent_did = tcx.opt_parent(self.mir_def_id().to_def_id())?;
if tcx.parent(region.def_id) != body_parent_did
|| tcx.def_kind(body_parent_did) != DefKind::Impl
{
return None;
}

let mut found = false;
tcx.fold_regions(tcx.type_of(body_parent_did), &mut true, |r: ty::Region<'tcx>, _| {
if *r == ty::ReEarlyBound(region) {
found = true;
}
r
});

Some(RegionName {
name: self.synthesize_region_name(),
source: RegionNameSource::AnonRegionFromImplSignature(
tcx.def_span(region.def_id),
// FIXME(compiler-errors): Does this ever actually show up
// anywhere other than the self type? I couldn't create an
// example of a `'_` in the impl's trait being referenceable.
if found { "self type" } else { "header" },
),
})
}
}
1 change: 1 addition & 0 deletions compiler/rustc_builtin_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_parse = { path = "../rustc_parse" }
rustc_target = { path = "../rustc_target" }
rustc_session = { path = "../rustc_session" }
Expand Down
24 changes: 19 additions & 5 deletions compiler/rustc_builtin_macros/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_attr as attr;
use rustc_errors::PResult;
use rustc_expand::base::{self, *};
use rustc_macros::SessionDiagnostic;
use rustc_span::Span;

pub fn expand_cfg(
Expand All @@ -34,21 +35,34 @@ pub fn expand_cfg(
}
}

fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
#[derive(SessionDiagnostic)]
#[error(slug = "builtin-macros-requires-cfg-pattern")]
struct RequiresCfgPattern {
#[primary_span]
#[label]
span: Span,
}

#[derive(SessionDiagnostic)]
#[error(slug = "builtin-macros-expected-one-cfg-pattern")]
struct OneCfgPattern {
#[primary_span]
span: Span,
}

fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
let mut p = cx.new_parser_from_tts(tts);

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

let cfg = p.parse_meta_item()?;

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

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

Ok(cfg)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ impl<'a> Linker for EmLinker<'a> {
fn no_crt_objects(&mut self) {}

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

fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
builtin-macros-requires-cfg-pattern =
macro requires a cfg-pattern as an argument
.label = cfg-pattern required

builtin-macros-expected-one-cfg-pattern = expected 1 cfg-pattern
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
fluent_messages! {
parser => "../locales/en-US/parser.ftl",
typeck => "../locales/en-US/typeck.ftl",
builtin_macros => "../locales/en-US/builtin_macros.ftl",
}

pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::BuiltinLintDiagnostics;
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_session::{parse::ParseSess, Limit, Session, SessionDiagnostic};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
Expand Down Expand Up @@ -1085,6 +1085,17 @@ impl<'a> ExtCtxt<'a> {
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
}

pub fn create_err(
&self,
err: impl SessionDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.sess.create_err(err)
}

pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
self.sess.emit_err(err)
}

/// Emit `msg` attached to `sp`, without immediately stopping
/// compilation.
///
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ macro_rules! pluralize {
("is", $x:expr) => {
if $x == 1 { "is" } else { "are" }
};
("was", $x:expr) => {
if $x == 1 { "was" } else { "were" }
};
("this", $x:expr) => {
if $x == 1 { "this" } else { "these" }
};
Expand Down
22 changes: 18 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,10 +2145,7 @@ impl<'tcx> Place<'tcx> {
pub fn iter_projections(
self,
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
self.projection.iter().enumerate().map(move |(i, proj)| {
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
(base, proj)
})
self.as_ref().iter_projections()
}

/// Generates a new place by appending `more_projections` to the existing ones
Expand Down Expand Up @@ -2208,6 +2205,23 @@ impl<'tcx> PlaceRef<'tcx> {
None
}
}

/// Iterate over the projections in evaluation order, i.e., the first element is the base with
/// its projection and then subsequently more projections are added.
/// As a concrete example, given the place a.b.c, this would yield:
/// - (a, .b)
/// - (a.b, .c)
///
/// Given a place without projections, the iterator is empty.
#[inline]
pub fn iter_projections(
self,
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
self.projection.iter().enumerate().map(move |(i, proj)| {
let base = PlaceRef { local: self.local, projection: &self.projection[..i] };
(base, *proj)
})
}
}

impl Debug for Place<'_> {
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use std::mem;
use std::ops::{Bound, Deref};
use std::sync::Arc;

use super::RvalueScopes;
use super::{ImplPolarity, RvalueScopes};

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

/// Given a `ty`, return whether it's an `impl Future<...>`.
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
let ty::Opaque(def_id, _) = ty.kind() else { return false };
let future_trait = self.lang_items().future_trait().unwrap();

self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
return false;
};
trait_predicate.trait_ref.def_id == future_trait
&& trait_predicate.polarity == ImplPolarity::Positive
})
}

/// Computes the def-ids of the transitive supertraits of `trait_def_id`. This (intentionally)
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
/// to identify which traits may define a given associated type to help avoid cycle errors.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ impl<'a> Resolver<'a> {
return PathResult::NonModule(PartialRes::new(Res::Err));
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
self.lint_if_path_starts_with_module(finalize, path, second_binding);
record_segment_res(self, res);
return PathResult::NonModule(PartialRes::with_unresolved_segments(
res,
path.len() - i - 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn target() -> Target {
linker: None,
is_like_emscripten: true,
panic_strategy: PanicStrategy::Unwind,
no_default_libraries: false,
post_link_args,
families: cvs!["unix", "wasm"],
..options
Expand Down
Loading