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 9 pull requests #94332

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c00f635
Remove in-band lifetimes
compiler-errors Feb 10, 2022
43dbd83
Remove LifetimeDefOrigin
compiler-errors Feb 20, 2022
8ca47d7
Stop manually SIMDing in swap_nonoverlapping
scottmcm Feb 21, 2022
da896d3
Improve CheckCfg internal representation
Urgau Feb 19, 2022
fbe1c15
Add test for well known names defined by rustc
Urgau Feb 19, 2022
3d23477
Improve diagnostic of the unexpected_cfgs lint
Urgau Feb 19, 2022
8d3de56
Continue improvements on the --check-cfg implementation
Urgau Feb 20, 2022
a556a2a
Add compiler flag `--check-cfg` to the unstable book
Urgau Feb 21, 2022
c73a2f8
properly handle fat pointers to uninhabitable types
compiler-errors Feb 23, 2022
f047af2
Normalize main return type during mono item collection & codegen
tmiasko Feb 23, 2022
37d9ea7
Improve `scan_escape`.
nnethercote Feb 24, 2022
44308dc
Inline a hot closure in `from_lit_token`.
nnethercote Feb 24, 2022
70018c1
update auto trait lint
lcnr Feb 24, 2022
34319ff
Avoid emitting full macro body into JSON
Mark-Simulacrum Feb 24, 2022
8ba7436
better ObligationCause for normalization errors in can_type_implement…
compiler-errors Feb 6, 2022
ee98dc8
restore spans for issue-50480
compiler-errors Feb 6, 2022
d22412e
Rollup merge of #93714 - compiler-errors:can-type-impl-copy-error-spa…
Dylan-DPC Feb 24, 2022
41ad5e7
Rollup merge of #93845 - compiler-errors:in-band-lifetimes, r=cjgillot
Dylan-DPC Feb 24, 2022
ce99d7b
Rollup merge of #94175 - Urgau:check-cfg-improvements, r=petrochenkov
Dylan-DPC Feb 24, 2022
6b4b6de
Rollup merge of #94212 - scottmcm:swapper, r=dtolnay
Dylan-DPC Feb 24, 2022
0e9c927
Rollup merge of #94242 - compiler-errors:fat-uninhabitable-pointer, r…
Dylan-DPC Feb 24, 2022
266c665
Rollup merge of #94308 - tmiasko:normalize-main-ret-ty, r=oli-obk
Dylan-DPC Feb 24, 2022
dd2c56e
Rollup merge of #94315 - lcnr:auto-trait-lint-update, r=oli-obk
Dylan-DPC Feb 24, 2022
5ad185a
Rollup merge of #94316 - nnethercote:improve-string-literal-unescapin…
Dylan-DPC Feb 24, 2022
7be2674
Rollup merge of #94327 - Mark-Simulacrum:avoid-macro-sp, r=petrochenkov
Dylan-DPC Feb 24, 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 compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![feature(min_specialization)]
#![recursion_limit = "256"]
#![feature(slice_internals)]
#![feature(stmt_expr_attributes)]

#[macro_use]
extern crate rustc_macros;
Expand Down
39 changes: 22 additions & 17 deletions compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,30 @@ impl LitKind {
// new symbol because the string in the LitKind is different to the
// string in the token.
let s = symbol.as_str();
let symbol =
if s.contains(&['\\', '\r']) {
let mut buf = String::with_capacity(s.len());
let mut error = Ok(());
unescape_literal(&s, Mode::Str, &mut |_, unescaped_char| {
match unescaped_char {
Ok(c) => buf.push(c),
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
let symbol = if s.contains(&['\\', '\r']) {
let mut buf = String::with_capacity(s.len());
let mut error = Ok(());
// Force-inlining here is aggressive but the closure is
// called on every char in the string, so it can be
// hot in programs with many long strings.
unescape_literal(
&s,
Mode::Str,
&mut #[inline(always)]
|_, unescaped_char| match unescaped_char {
Ok(c) => buf.push(c),
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
}
});
error?;
Symbol::intern(&buf)
} else {
symbol
};
},
);
error?;
Symbol::intern(&buf)
} else {
symbol
};
LitKind::Str(symbol, ast::StrStyle::Cooked)
}
token::StrRaw(n) => {
Expand Down
57 changes: 12 additions & 45 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,9 @@ struct LoweringContext<'a, 'hir: 'a> {
/// indicate whether or not we're in a place where new lifetimes will result
/// in in-band lifetime definitions, such a function or an impl header,
/// including implicit lifetimes from `impl_header_lifetime_elision`.
is_collecting_in_band_lifetimes: bool,
is_collecting_anonymous_lifetimes: bool,

/// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
/// When `is_collecting_in_band_lifetimes` is true, each lifetime is checked
/// against this list to see if it is already in-scope, or if a definition
/// needs to be created for it.
///
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
/// vector.
in_scope_lifetimes: Vec<ParamName>,
Expand Down Expand Up @@ -377,7 +373,7 @@ pub fn lower_crate<'a, 'hir>(
task_context: None,
current_item: None,
lifetimes_to_define: Vec::new(),
is_collecting_in_band_lifetimes: false,
is_collecting_anonymous_lifetimes: false,
in_scope_lifetimes: Vec::new(),
allow_try_trait: Some([sym::try_trait_v2][..].into()),
allow_gen_future: Some([sym::gen_future][..].into()),
Expand Down Expand Up @@ -724,13 +720,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
f: impl FnOnce(&mut Self) -> T,
) -> (Vec<(Span, ParamName)>, T) {
let was_collecting = std::mem::replace(&mut self.is_collecting_in_band_lifetimes, true);
let was_collecting = std::mem::replace(&mut self.is_collecting_anonymous_lifetimes, true);
let len = self.lifetimes_to_define.len();

let res = f(self);

let lifetimes_to_define = self.lifetimes_to_define.split_off(len);
self.is_collecting_in_band_lifetimes = was_collecting;
self.is_collecting_anonymous_lifetimes = was_collecting;
(lifetimes_to_define, res)
}

Expand All @@ -747,7 +743,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// that collisions are ok here and this shouldn't
// really show up for end-user.
let (str_name, kind) = match hir_name {
ParamName::Plain(ident) => (ident.name, hir::LifetimeParamKind::InBand),
ParamName::Plain(ident) => (ident.name, hir::LifetimeParamKind::Explicit),
ParamName::Fresh(_) => (kw::UnderscoreLifetime, hir::LifetimeParamKind::Elided),
ParamName::Error => (kw::UnderscoreLifetime, hir::LifetimeParamKind::Error),
};
Expand All @@ -771,38 +767,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}

/// When there is a reference to some lifetime `'a`, and in-band
/// lifetimes are enabled, then we want to push that lifetime into
/// the vector of names to define later. In that case, it will get
/// added to the appropriate generics.
fn maybe_collect_in_band_lifetime(&mut self, ident: Ident) {
if !self.is_collecting_in_band_lifetimes {
return;
}

if !self.sess.features_untracked().in_band_lifetimes {
return;
}

if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.normalize_to_macros_2_0())) {
return;
}

let hir_name = ParamName::Plain(ident);

if self.lifetimes_to_define.iter().any(|(_, lt_name)| {
lt_name.normalize_to_macros_2_0() == hir_name.normalize_to_macros_2_0()
}) {
return;
}

self.lifetimes_to_define.push((ident.span, hir_name));
}

/// When we have either an elided or `'_` lifetime in an impl
/// header, we convert it to an in-band lifetime.
fn collect_fresh_in_band_lifetime(&mut self, span: Span) -> ParamName {
assert!(self.is_collecting_in_band_lifetimes);
fn collect_fresh_anonymous_lifetime(&mut self, span: Span) -> ParamName {
assert!(self.is_collecting_anonymous_lifetimes);
let index = self.lifetimes_to_define.len() + self.in_scope_lifetimes.len();
let hir_name = ParamName::Fresh(index);
self.lifetimes_to_define.push((span, hir_name));
Expand Down Expand Up @@ -1944,7 +1912,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
ident if ident.name == kw::UnderscoreLifetime => match self.anonymous_lifetime_mode {
AnonymousLifetimeMode::CreateParameter => {
let fresh_name = self.collect_fresh_in_band_lifetime(span);
let fresh_name = self.collect_fresh_anonymous_lifetime(span);
self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(fresh_name))
}

Expand All @@ -1955,7 +1923,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
AnonymousLifetimeMode::ReportError => self.new_error_lifetime(Some(l.id), span),
},
ident => {
self.maybe_collect_in_band_lifetime(ident);
let param_name = ParamName::Plain(self.lower_ident(ident));
self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(param_name))
}
Expand Down Expand Up @@ -1999,8 +1966,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let (name, kind) = match param.kind {
GenericParamKind::Lifetime => {
let was_collecting_in_band = self.is_collecting_in_band_lifetimes;
self.is_collecting_in_band_lifetimes = false;
let was_collecting_in_band = self.is_collecting_anonymous_lifetimes;
self.is_collecting_anonymous_lifetimes = false;

let lt = self
.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
Expand All @@ -2023,7 +1990,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let kind =
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };

self.is_collecting_in_band_lifetimes = was_collecting_in_band;
self.is_collecting_anonymous_lifetimes = was_collecting_in_band;

(param_name, kind)
}
Expand Down Expand Up @@ -2382,7 +2349,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Hence `impl Foo for &u32` becomes `impl<'f> Foo for &'f u32` for some fresh
// `'f`.
AnonymousLifetimeMode::CreateParameter => {
let fresh_name = self.collect_fresh_in_band_lifetime(span);
let fresh_name = self.collect_fresh_anonymous_lifetime(span);
hir::Lifetime {
hir_id: self.next_id(),
span: self.lower_span(span),
Expand Down
41 changes: 25 additions & 16 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_errors::{struct_span_err, Applicability};
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
use rustc_macros::HashStable_Generic;
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_session::parse::{feature_err, ParseSess};
use rustc_session::Session;
use rustc_span::hygiene::Transparency;
Expand Down Expand Up @@ -461,29 +462,37 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
true
}
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
let name = cfg.ident().expect("multi-segment cfg predicate").name;
let ident = cfg.ident().expect("multi-segment cfg predicate");
let name = ident.name;
let value = cfg.value_str();
if sess.check_config.names_checked && !sess.check_config.names_valid.contains(&name)
{
sess.buffer_lint(
UNEXPECTED_CFGS,
cfg.span,
CRATE_NODE_ID,
"unexpected `cfg` condition name",
);
}
if let Some(val) = value {
if sess.check_config.values_checked.contains(&name)
&& !sess.check_config.values_valid.contains(&(name, val))
{
sess.buffer_lint(
if let Some(names_valid) = &sess.check_config.names_valid {
if !names_valid.contains(&name) {
sess.buffer_lint_with_diagnostic(
UNEXPECTED_CFGS,
cfg.span,
CRATE_NODE_ID,
"unexpected `cfg` condition value",
"unexpected `cfg` condition name",
BuiltinLintDiagnostics::UnexpectedCfg(ident.span, name, None),
);
}
}
if let Some(value) = value {
if let Some(values) = &sess.check_config.values_valid.get(&name) {
if !values.contains(&value) {
sess.buffer_lint_with_diagnostic(
UNEXPECTED_CFGS,
cfg.span,
CRATE_NODE_ID,
"unexpected `cfg` condition value",
BuiltinLintDiagnostics::UnexpectedCfg(
cfg.name_value_literal_span().unwrap(),
name,
Some(value),
),
);
}
}
}
sess.config.contains(&(name, value))
}
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub(crate) fn maybe_create_entry_wrapper(
// late-bound regions, since late-bound
// regions must appear in the argument
// listing.
let main_ret_ty = tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
let main_ret_ty = tcx.normalize_erasing_regions(
ty::ParamEnv::reveal_all(),
main_ret_ty.no_bound_vars().unwrap(),
);

let cmain_sig = Signature {
params: vec![
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ fn pointer_or_reference_metadata<'ll, 'tcx>(
// This is a thin pointer. Create a regular pointer type and give it the correct name.
debug_assert_eq!(
(thin_pointer_size, thin_pointer_align),
cx.size_and_align_of(ptr_type)
cx.size_and_align_of(ptr_type),
"ptr_type={}, pointee_type={}",
ptr_type,
pointee_type,
);

unsafe {
Expand Down
33 changes: 16 additions & 17 deletions compiler/rustc_codegen_llvm/src/debuginfo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use super::namespace::item_namespace;
use super::CrateDebugContext;

use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
use rustc_middle::ty::{self, DefIdTree, Ty};
use rustc_target::abi::Variants;
use tracing::trace;

use crate::common::CodegenCx;
use crate::llvm;
Expand Down Expand Up @@ -63,38 +63,37 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
pointee_ty: Ty<'tcx>,
) -> Option<FatPtrKind> {
let layout = cx.layout_of(pointee_ty);
let pointee_tail_ty = cx.tcx.struct_tail_erasing_lifetimes(pointee_ty, cx.param_env());
let layout = cx.layout_of(pointee_tail_ty);
trace!(
"fat_pointer_kind: {:?} has layout {:?} (is_unsized? {})",
pointee_tail_ty,
layout,
layout.is_unsized()
);

if !layout.is_unsized() {
return None;
}

match *pointee_ty.kind() {
match *pointee_tail_ty.kind() {
ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice),
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
ty::Adt(..) | ty::Tuple(..) if matches!(layout.variants, Variants::Single { .. }) => {
let last_field_index = layout.fields.count() - 1;
debug_assert!(
(0..last_field_index)
.all(|field_index| { !layout.field(cx, field_index).is_unsized() })
);

let unsized_field = layout.field(cx, last_field_index);
debug_assert!(unsized_field.is_unsized());
fat_pointer_kind(cx, unsized_field.ty)
}
ty::Foreign(_) => {
// Assert that pointers to foreign types really are thin:
debug_assert_eq!(
cx.size_of(cx.tcx.mk_imm_ptr(pointee_ty)),
cx.size_of(cx.tcx.mk_imm_ptr(pointee_tail_ty)),
cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8))
);
None
}
_ => {
// For all other pointee types we should already have returned None
// at the beginning of the function.
panic!("fat_pointer_kind() - Encountered unexpected `pointee_ty`: {:?}", pointee_ty)
panic!(
"fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {:?}",
pointee_tail_ty
)
}
}
}
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// late-bound regions, since late-bound
// regions must appear in the argument
// listing.
let main_ret_ty = cx.tcx().erase_regions(main_ret_ty.no_bound_vars().unwrap());
let main_ret_ty = cx.tcx().normalize_erasing_regions(
ty::ParamEnv::reveal_all(),
main_ret_ty.no_bound_vars().unwrap(),
);

let Some(llfn) = cx.declare_c_main(llfty) else {
// FIXME: We should be smart and show a better diagnostic here.
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0687.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

In-band lifetimes cannot be used in `fn`/`Fn` syntax.

Erroneous code examples:

```compile_fail,E0687
```ignore (feature got removed)
#![feature(in_band_lifetimes)]

fn foo(x: fn(&'a u32)) {} // error!
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0688.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

In-band lifetimes were mixed with explicit lifetime binders.

Erroneous code example:

```compile_fail,E0688
```ignore (feature got removed)
#![feature(in_band_lifetimes)]

fn foo<'a>(x: &'a u32, y: &'b u32) {} // error!
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,14 @@ impl DiagnosticSpan {
let end = je.sm.lookup_char_pos(span.hi());
let backtrace_step = backtrace.next().map(|bt| {
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
let def_site_span =
Self::from_span_full(bt.def_site, false, None, None, [].into_iter(), je);
let def_site_span = Self::from_span_full(
je.sm.guess_head_span(bt.def_site),
false,
None,
None,
[].into_iter(),
je,
);
Box::new(DiagnosticSpanMacroExpansion {
span: call_site,
macro_decl_name: bt.kind.descr(),
Expand Down
Loading