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 7 pull requests #77297

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
01f65af
diag: improve closure/generic parameter mismatch
davidtwco Sep 14, 2020
8aae1ee
Move cell exterior test into library unit tests
poliorcetics Sep 7, 2020
f69c5aa
Move more tests using Cell to unit tests
poliorcetics Sep 7, 2020
af44a2a
move 'cell does not clone' test
poliorcetics Sep 8, 2020
fc152cd
move 'test zip ...' tests
poliorcetics Sep 8, 2020
85b2d9b
fmt
poliorcetics Sep 8, 2020
949c966
move format! interface tests
poliorcetics Sep 8, 2020
ed52c7b
Move deref-lval test
poliorcetics Sep 8, 2020
ac39deb
Move panic safety traits tests
poliorcetics Sep 10, 2020
8904921
Move array cycle test
poliorcetics Sep 10, 2020
275eed7
Move vec-slice-drop test
poliorcetics Sep 10, 2020
6bc0357
Move vec-cycle test
poliorcetics Sep 10, 2020
f6a4189
Move vec-cycle-wrapped test
poliorcetics Sep 11, 2020
5be843f
Move format-ref-cell test
poliorcetics Sep 13, 2020
1994cee
Add alias for iterator fold
pickfire Sep 25, 2020
ea0065a
Reposition iterator doc alias reduce before inline
pickfire Sep 25, 2020
a61b963
review: fix nits and move panic safety tests to the correct place
poliorcetics Sep 25, 2020
71bc62b
Add option to pass a custom codegen backend from a driver
bjorn3 Sep 8, 2020
2532a7e
expand: Stop un-interpolating `NtIdent`s before passing them to built…
petrochenkov Sep 27, 2020
3b27799
expand: Minor fn ptr call cleanup
petrochenkov Sep 27, 2020
1ff1431
Add a feature gate for basic function pointer use in `const fn`
ecstatic-morse Sep 24, 2020
3cbd17f
Remove `rustc_allow_const_fn_ptr`
ecstatic-morse Sep 24, 2020
e2622b9
Update tests with new feature gate
ecstatic-morse Sep 24, 2020
54d3329
Bless tests
ecstatic-morse Sep 24, 2020
368502c
Mark `min_const_fn_fn_ptr` test as gate test
ecstatic-morse Sep 24, 2020
807260b
Remove feature gate test for `rustc_allow_const_fn_ptr`
ecstatic-morse Sep 27, 2020
dc8414b
fix building libstd for Miri on macOS
RalfJung Sep 28, 2020
f9dfbb4
Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad
RalfJung Sep 28, 2020
94d13bb
Rollup merge of #76474 - bjorn3:driver_selected_codegen, r=oli-obk
RalfJung Sep 28, 2020
fef6a2d
Rollup merge of #76711 - davidtwco:issue-51154-param-closure, r=estebank
RalfJung Sep 28, 2020
a43ee0c
Rollup merge of #77170 - ecstatic-morse:const-fn-ptr, r=oli-obk
RalfJung Sep 28, 2020
29ff334
Rollup merge of #77194 - pickfire:patch-7, r=withoutboats
RalfJung Sep 28, 2020
a9a364f
Rollup merge of #77275 - petrochenkov:interpid, r=varkor
RalfJung Sep 28, 2020
a99fb78
Rollup merge of #77288 - RalfJung:miri-macos, r=Amanieu
RalfJung Sep 28, 2020
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
31 changes: 7 additions & 24 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ pub struct ConstStability {
pub feature: Symbol,
/// whether the function has a `#[rustc_promotable]` attribute
pub promotable: bool,
/// whether the function has a `#[rustc_allow_const_fn_ptr]` attribute
pub allow_const_fn_ptr: bool,
}

/// The available stability levels.
Expand Down Expand Up @@ -190,7 +188,6 @@ where
let mut stab: Option<Stability> = None;
let mut const_stab: Option<ConstStability> = None;
let mut promotable = false;
let mut allow_const_fn_ptr = false;
let diagnostic = &sess.parse_sess.span_diagnostic;

'outer: for attr in attrs_iter {
Expand All @@ -200,7 +197,6 @@ where
sym::unstable,
sym::stable,
sym::rustc_promotable,
sym::rustc_allow_const_fn_ptr,
]
.iter()
.any(|&s| attr.has_name(s))
Expand All @@ -215,9 +211,6 @@ where
if attr.has_name(sym::rustc_promotable) {
promotable = true;
}
if attr.has_name(sym::rustc_allow_const_fn_ptr) {
allow_const_fn_ptr = true;
}
// attributes with data
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
let meta = meta.as_ref().unwrap();
Expand Down Expand Up @@ -360,12 +353,8 @@ where
if sym::unstable == meta_name {
stab = Some(Stability { level, feature });
} else {
const_stab = Some(ConstStability {
level,
feature,
promotable: false,
allow_const_fn_ptr: false,
});
const_stab =
Some(ConstStability { level, feature, promotable: false });
}
}
(None, _, _) => {
Expand Down Expand Up @@ -440,12 +429,8 @@ where
if sym::stable == meta_name {
stab = Some(Stability { level, feature });
} else {
const_stab = Some(ConstStability {
level,
feature,
promotable: false,
allow_const_fn_ptr: false,
});
const_stab =
Some(ConstStability { level, feature, promotable: false });
}
}
(None, _) => {
Expand All @@ -464,18 +449,16 @@ where
}

// Merge the const-unstable info into the stability info
if promotable || allow_const_fn_ptr {
if promotable {
if let Some(ref mut stab) = const_stab {
stab.promotable = promotable;
stab.allow_const_fn_ptr = allow_const_fn_ptr;
} else {
struct_span_err!(
diagnostic,
item_sp,
E0717,
"rustc_promotable and rustc_allow_const_fn_ptr attributes \
must be paired with either a rustc_const_unstable or a rustc_const_stable \
attribute"
"`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` \
or a `rustc_const_stable` attribute"
)
.emit();
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_builtin_macros/src/concat_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ pub fn expand_concat_idents<'cx>(
}
}
} else {
match e {
TokenTree::Token(Token { kind: token::Ident(name, _), .. }) => {
res_str.push_str(&name.as_str())
}
_ => {
cx.span_err(sp, "concat_idents! requires ident args.");
return DummyResult::any(sp);
if let TokenTree::Token(token) = e {
if let Some((ident, _)) = token.ident() {
res_str.push_str(&ident.name.as_str());
continue;
}
}

cx.span_err(sp, "concat_idents! requires ident args.");
return DummyResult::any(sp);
}
}

Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ pub fn run_compiler(
callbacks: &mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
emitter: Option<Box<dyn Write + Send>>,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
) -> interface::Result<()> {
let mut args = Vec::new();
for arg in at_args {
Expand All @@ -162,6 +165,11 @@ pub fn run_compiler(
let sopts = config::build_session_options(&matches);
let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg"));

// We wrap `make_codegen_backend` in another `Option` such that `dummy_config` can take
// ownership of it when necessary, while also allowing the non-dummy config to take ownership
// when `dummy_config` is not used.
let mut make_codegen_backend = Some(make_codegen_backend);

let mut dummy_config = |sopts, cfg, diagnostic_output| {
let mut config = interface::Config {
opts: sopts,
Expand All @@ -177,6 +185,7 @@ pub fn run_compiler(
lint_caps: Default::default(),
register_lints: None,
override_queries: None,
make_codegen_backend: make_codegen_backend.take().unwrap(),
registry: diagnostics_registry(),
};
callbacks.config(&mut config);
Expand Down Expand Up @@ -253,6 +262,7 @@ pub fn run_compiler(
lint_caps: Default::default(),
register_lints: None,
override_queries: None,
make_codegen_backend: make_codegen_backend.unwrap(),
registry: diagnostics_registry(),
};

Expand Down Expand Up @@ -1265,7 +1275,7 @@ pub fn main() -> ! {
})
})
.collect::<Vec<_>>();
run_compiler(&args, &mut callbacks, None, None)
run_compiler(&args, &mut callbacks, None, None, None)
});
// The extra `\t` is necessary to align this label with the others.
print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed());
Expand Down
33 changes: 5 additions & 28 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::expand::{self, AstFragment, Invocation};
use crate::module::DirectoryOwnership;

use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::{self, TokenStream};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{AssocCtxt, Visitor};
use rustc_ast::{self as ast, Attribute, NodeId, PatKind};
use rustc_attr::{self as attr, Deprecation, HasAttrs, Stability};
Expand Down Expand Up @@ -313,7 +312,7 @@ where
ts: TokenStream,
) -> Result<TokenStream, ErrorReported> {
// FIXME setup implicit context in TLS before calling self.
Ok((*self)(ts))
Ok(self(ts))
}
}

Expand All @@ -339,7 +338,7 @@ where
annotated: TokenStream,
) -> Result<TokenStream, ErrorReported> {
// FIXME setup implicit context in TLS before calling self.
Ok((*self)(annotation, annotated))
Ok(self(annotation, annotated))
}
}

Expand All @@ -364,31 +363,9 @@ where
&self,
ecx: &'cx mut ExtCtxt<'_>,
span: Span,
mut input: TokenStream,
input: TokenStream,
) -> Box<dyn MacResult + 'cx> {
struct AvoidInterpolatedIdents;

impl MutVisitor for AvoidInterpolatedIdents {
fn visit_tt(&mut self, tt: &mut tokenstream::TokenTree) {
if let tokenstream::TokenTree::Token(token) = tt {
if let token::Interpolated(nt) = &token.kind {
if let token::NtIdent(ident, is_raw) = **nt {
*tt = tokenstream::TokenTree::token(
token::Ident(ident.name, is_raw),
ident.span,
);
}
}
}
mut_visit::noop_visit_tt(tt, self)
}

fn visit_mac(&mut self, mac: &mut ast::MacCall) {
mut_visit::noop_visit_mac(mac, self)
}
}
AvoidInterpolatedIdents.visit_tts(&mut input);
(*self)(ecx, span, input)
self(ecx, span, input)
}
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ declare_features! (
/// Allows basic arithmetic on floating point types in a `const fn`.
(active, const_fn_floating_point_arithmetic, "1.48.0", Some(57241), None),

/// Allows using and casting function pointers in a `const fn`.
(active, const_fn_fn_ptr_basics, "1.48.0", Some(57563), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================

rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
rustc_attr!(rustc_allow_const_fn_ptr, AssumedUsed, template!(Word), IMPL_DETAIL),
rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),

// ==========================================================================
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ pub struct Config {
pub override_queries:
Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::Providers)>,

/// This is a callback from the driver that is called to create a codegen backend.
pub make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,

/// Registry of diagnostics codes.
pub registry: Registry,
}
Expand All @@ -167,6 +171,7 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
config.file_loader,
config.input_path.clone(),
config.lint_caps,
config.make_codegen_backend,
registry.clone(),
);

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ pub fn create_session(
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
input_path: Option<PathBuf>,
lint_caps: FxHashMap<lint::LintId, lint::Level>,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
descriptions: Registry,
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>) {
let codegen_backend = get_codegen_backend(&sopts);
let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend {
make_codegen_backend(&sopts)
} else {
get_codegen_backend(&sopts)
};

// target_override is documented to be called before init(), so this is okay
let target_override = codegen_backend.target_override(&sopts);

Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ rustc_queries! {
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
}

query const_fn_is_allowed_fn_ptr(key: DefId) -> bool {
desc { |tcx| "checking if const fn allows `fn()` types: `{}`", tcx.def_path_str(key) }
}

/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
query is_foreign_item(key: DefId) -> bool {
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,18 @@ impl<T> Trait<T> for X {
#traits-as-parameters",
);
}
(ty::Param(p), ty::Closure(..) | ty::Generator(..)) => {
let generics = self.generics_of(body_owner_def_id);
let p_span = self.def_span(generics.type_param(p, self).def_id);
if !sp.contains(p_span) {
db.span_label(p_span, "this type parameter");
}
db.help(&format!(
"every closure has a distinct type and so could not always match the \
caller-chosen type of parameter `{}`",
p
));
}
(ty::Param(p), _) | (_, ty::Param(p)) => {
let generics = self.generics_of(body_owner_def_id);
let p_span = self.def_span(generics.type_param(p, self).def_id);
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_mir/src/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,11 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}
}

fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
is_const_fn(tcx, def_id)
&& tcx.lookup_const_stability(def_id).map(|stab| stab.allow_const_fn_ptr).unwrap_or(false)
}

pub fn provide(providers: &mut Providers) {
*providers = Providers {
is_const_fn_raw,
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
is_promotable_const_fn,
const_fn_is_allowed_fn_ptr,
..*providers
};
}
28 changes: 21 additions & 7 deletions compiler/rustc_mir/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,21 @@ impl NonConstOp for FnPtrCast {
const STOPS_CONST_CHECKING: bool = true;

fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
mcf_status_in_item(ccx)
if ccx.const_kind() != hir::ConstContext::ConstFn {
Status::Allowed
} else {
Status::Unstable(sym::const_fn_fn_ptr_basics)
}
}

fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
mcf_emit_error(ccx, span, "function pointer casts are not allowed in const fn");
feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_fn_fn_ptr_basics,
span,
&format!("function pointer casts are not allowed in {}s", ccx.const_kind()),
)
.emit()
}
}

Expand Down Expand Up @@ -596,17 +606,21 @@ pub mod ty {
const STOPS_CONST_CHECKING: bool = true;

fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
// FIXME: This attribute a hack to allow the specialization of the `futures` API. See
// #59739. We should have a proper feature gate for this.
if ccx.tcx.has_attr(ccx.def_id.to_def_id(), sym::rustc_allow_const_fn_ptr) {
if ccx.const_kind() != hir::ConstContext::ConstFn {
Status::Allowed
} else {
mcf_status_in_item(ccx)
Status::Unstable(sym::const_fn_fn_ptr_basics)
}
}

fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
mcf_emit_error(ccx, span, "function pointers in const fn are unstable");
feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_fn_fn_ptr_basics,
span,
&format!("function pointers cannot appear in {}s", ccx.const_kind()),
)
.emit()
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ symbols! {
const_extern_fn,
const_fn,
const_fn_floating_point_arithmetic,
const_fn_fn_ptr_basics,
const_fn_transmute,
const_fn_union,
const_generics,
Expand Down Expand Up @@ -884,7 +885,6 @@ symbols! {
rustc,
rustc_allocator,
rustc_allocator_nounwind,
rustc_allow_const_fn_ptr,
rustc_args_required_const,
rustc_attrs,
rustc_builtin_macro,
Expand Down
Loading